<script setup lang="ts">

import { ref } from 'vue'
import { onLoad, onShareAppMessage, onShareTimeline } from '@dcloudio/uni-app'
import { getData } from '@/api/about'
import myParse from '@/components/loading-parse'
import IndexTitle from '@/pages/walls/index-title.vue'
import useShare from '@/mixins/share'
import { shareUtils } from '@/utils/share'

const { getShareCover } = useShare()



const data = ref([])
onLoad(() => {
  getData().then(res => {
    data.value = res
  })

 
})

const handleRightText = (item) => {

  uni.navigateTo({
    url: `/pages/about-forone/detail?id=${item.id}`
  })


}


const page = getCurrentPages().pop()
let path: string = page.route

const share_path = shareUtils.buildPathQuery(path)
onShareAppMessage(() => {

  const promise = new Promise(resolve => {
    getShareCover(path, null, null).then(res => {

      res.path = share_path

      debugger
      resolve(res)

    })
  })

  return {
    path: share_path,
    imageUrl: null,
    promise
  }
})



onShareTimeline(() => {

  const promise = new Promise(resolve => {
    getShareCover(path, null, null).then(res => {

      res.path = share_path

      debugger
      resolve(res)

    })
  })

  return {
    path: share_path,
    imageUrl: null,
    promise
  }
})

const handleTapDealer = (dealer)=>{

  uni.navigateTo({
    url: `/pages/about-forone/dealer-content?id=${dealer.id}`
  })

}


</script>

<template>
  <ForOneHeader />
  <MidLayout>
    <view v-for="item, index in data">
      <IndexTitle :zh_text="item.title" :en_text="item.en_title" @handleRightText="handleRightText(item)"
        :rightText="item.is_show_click_to_all_btn == '1' ? '查看全部' : ''" :open_type="item.open_type" :official_account_article_url="item.official_account_article_url"/>
      
        <view v-if="item.is_show_button == '1'">

          <view class="layout-1">
            <view class="layout-1-item" v-for="_item, _index in item.button" :key="_index">
              <up-image :src="_item.button_url" @tap="handleTapDealer(_item)" radius="8" width="100%" height="300rpx"
                mode='aspectFill' :showMenuByLongpress="false"></up-image>
            </view>
          </view>

        </view>
        <myParse :content="item.content" v-if="item.content" />

    </view>
  </MidLayout>
</template>

<style scoped lang="scss">
.layout-1 {
  display: flex;
  flex-direction: row;
  gap: 10rpx;

  padding-bottom: 10rpx;
  // height: 200rpx;
  .layout-1-item {
    flex: 1;
  }
}
</style>
